package com.zhida.smartcontrol.launch;

import android.os.Bundle;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.jay.tools.utils.ResUtil;
import com.jay.tools.utils.SharedUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.Keys;
import com.zhida.smartcontrol.launch.bottom.BaseBottomFragment;
import com.zhida.smartcontrol.launch.bottom.BottomItemFragment;
import com.zhida.smartcontrol.launch.bottom.BottomTabBean;
import com.zhida.smartcontrol.launch.bottom.ItemBuilder;
import com.zhida.smartcontrol.pagectrl.PageCtrlFragment;
import com.zhida.smartcontrol.pagectrl.ProjectListBean;
import com.zhida.smartcontrol.pagectrl.projectdetail.ProjectDetailFragment;
import com.zhida.smartcontrol.pagehome.PageHomeFragment;
import com.zhida.smartcontrol.pagehome.scan.ScanFragment;
import com.zhida.smartcontrol.pagemy.PageMyFragment;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/8/19 019 17:35
 * description: 入口
 */
public class EntryFragment extends BaseBottomFragment {

    public static EntryFragment newInstance() {
        Bundle args = new Bundle();
        EntryFragment fragment = new EntryFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public LinkedHashMap<BottomTabBean, BottomItemFragment> setItems(ItemBuilder builder) {
        LinkedHashMap<BottomTabBean, BottomItemFragment> items = new LinkedHashMap<>();
        items.put(new BottomTabBean(R.drawable.ic_home0, R.drawable.ic_home1, "首页"), new PageHomeFragment());
        String json = SharedUtil.getString(Keys.PROJECT_LIST, "");
        List<ProjectListBean> projectList = JSON.parseArray(json, ProjectListBean.class);
        if (projectList.size()!=1) {
            items.put(new BottomTabBean(R.drawable.ic_ctrl0, R.drawable.ic_ctrl1, "智控"), new PageCtrlFragment());
        }else {
            items.put(new BottomTabBean(R.drawable.ic_ctrl0, R.drawable.ic_ctrl1, "智控"), ProjectDetailFragment.newInstance(projectList.get(0).getProjectName(), projectList.get(0).getId(), ProjectDetailFragment.FROM_LOGIN));
        }
        items.put(new BottomTabBean(R.drawable.ic_wo0, R.drawable.ic_wo1, "我的"), new PageMyFragment());
        return builder.addItems(items).build();
    }

    @Override
    public int setIndexFragment() {
        return 0;
    }

    @Override
    public int setClickedColor() {
        return ResUtil.getColor(getProxyActivity(), R.color.c_437DFF);
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {

    }

}
